//
//  HMStatus.swift
//  weibo28
//
//  Created by 范英强 on 16/3/25.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMStatus: NSObject {
    
    var created_at: String?
    //微博id
    var id: Int64 = 0
    //微博正文
    var text: String?
    //微博来源
    var source: String?
    // 用户信息数据
    var user: HMUser?
    
    // 转发微博
    var retweeted_status:HMStatus?
    
    // 微博配图
    var pic_urls:[HMPictureInfo]?
    //int	转发数
    var reposts_count:Int = 0
    // 评论数
    var comments_count:Int = 0
    // 表态数
    var attitudes_count:Int	= 0
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            guard let dic = value as? [String: AnyObject] else{
                return
            }
            user = HMUser(dict: dic)
 
        }else if key == "retweeted_status"{
            
            guard let dic = value as? [String: AnyObject] else{
                return
            }
            
            retweeted_status = HMStatus(dict: dic)
            
        }else if key == "pic_urls"{
            
            guard let array = value as? [[String: AnyObject]] else{
                return
            }
            
            // 定义一个临时数据保存模型数据
            var tempArray = [HMPictureInfo]()
            
            // 遍历数组 字典转模型
            for dic in array{
                let pic = HMPictureInfo(dict: dic)
                tempArray.append(pic)
                
            }
            pic_urls = tempArray
        }else{
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }

}
